<?php
namespace app\index\validate;

use think\Validate;

class Mobile extends Validate
{
    protected $rule = [
        'phone'      =>  'checkPhone|require',
        'type'       =>  'require|integer|in:1,2,3,4,5',
    ];

    protected $message  =   [
        'phone.mobile' => '请输入正确的手机号',
        'phone.require' => '手机号不能为空',
        'type.require'   => '发送类型不能为空',
        'type.integer'  => '发送类型码为整数',
        'type.in'  => '非法请求的type值'
    ];

    /**
     * @param $value
     * @param $rule
     * @param array $data
     * @return bool|string
     */
    protected function checkPhone($value,$rule,$data=[])
    {
        $search = '/^0?1[3|4|5|6|7|8][0-9]\d{8}$/';
        if (preg_match($search,$value)){
            return $rule = true;
        }else{
            return $rule = '请输入正确的手机号';
        }
    }
}